package com.ruoyi.web.controller.personnel;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.personnel.domain.TeachingCertificate;
import com.ruoyi.personnel.service.ITeachingCertificateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 教师资格证Controller
 *
 * @author ruoyi
 * @date 2021-03-03
 */
@Api("教师资格证")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/teaching/certificate" )
public class TeachingCertificateController extends BaseController {

    private final ITeachingCertificateService iTeachingCertificateService;

    /**
     * 查询教师资格证列表
     */
    @ApiOperation("查询教师资格证列表")
    @PreAuthorize("@ss.hasPermi('teaching:certificate:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachingCertificate teachingCertificate) {
        startPage();
        List<TeachingCertificate> list = iTeachingCertificateService.queryList(teachingCertificate);
        return getDataTable(list);
    }

    /**
     * 导出教师资格证列表
     */
    @ApiOperation("导出教师资格证列表")
    @PreAuthorize("@ss.hasPermi('teaching:certificate:export')" )
    @Log(title = "教师资格证" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(TeachingCertificate teachingCertificate) {
        List<TeachingCertificate> list = iTeachingCertificateService.queryList(teachingCertificate);
        ExcelUtil<TeachingCertificate> util = new ExcelUtil<TeachingCertificate>(TeachingCertificate.class);
        return util.exportExcel(list, "certificate" );
    }

    /**
     * 获取教师资格证详细信息
     */
    @ApiOperation("获取教师资格证详细信息")
    @PreAuthorize("@ss.hasPermi('teaching:certificate:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) String id) {
        return AjaxResult.success(iTeachingCertificateService.getById(id));
    }

    /**
     * 新增教师资格证
     */
    @ApiOperation("新增教师资格证")
    @PreAuthorize("@ss.hasPermi('teaching:certificate:add')" )
    @Log(title = "教师资格证" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachingCertificate teachingCertificate) {
        teachingCertificate.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iTeachingCertificateService.save(teachingCertificate) ? 1 : 0);
    }

    /**
     * 修改教师资格证
     */
    @ApiOperation("修改教师资格证")
    @PreAuthorize("@ss.hasPermi('teaching:certificate:edit')" )
    @Log(title = "教师资格证" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingCertificate teachingCertificate) {
        return toAjax(iTeachingCertificateService.updateById(teachingCertificate) ? 1 : 0);
    }

    /**
     * 删除教师资格证
     */
    @ApiOperation("删除教师资格证")
    @PreAuthorize("@ss.hasPermi('teaching:certificate:remove')" )
    @Log(title = "教师资格证" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(iTeachingCertificateService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
